﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admincp_hocsinh : AdminPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        this.FillDataToListView();
    }

    private void FillDataToListView()
    {
        var hocsinh = (from hs in db.HocSinhs
                       select hs)
                       .AsEnumerable()
                       .Select((_hs, index) => new
                       {
                           SoThuTu = ++index,
                           MaHocSinh = _hs.MaHocSinh,
                           TenHocSinh = _hs.TenHocSinh,
                           DienThoai = _hs.DienThoai,
                           Email = _hs.Email,
                           TrangThai = _hs.TrangThai
                       });
        lvHocSinh.DataSource = hocsinh;
        lvHocSinh.DataBind();
    }

    protected void ThemMoiHocSinh(object sender, EventArgs e)
    {
        Response.Redirect("qlhocsinh.aspx?hanhdong=themmoi");
    }

    protected void lvHocSinh_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "EDIT":
                Response.Redirect("qlhocsinh.aspx?hanhdong=capnhat&mahocsinh=" + e.CommandArgument.ToString());
                break;
            case "DELETE":
                HocSinh hocsinh = db.HocSinhs.Single(hs=>hs.MaHocSinh == Int64.Parse(e.CommandArgument.ToString()));
                db.HocSinhs.DeleteOnSubmit(hocsinh);
                db.SubmitChanges();
                this.FillDataToListView();
                break;
        }
    }
    protected void lvHocSinh_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {

    }
    protected void lvHocSinh_ItemEditing(object sender, ListViewEditEventArgs e)
    {

    }
}